import os
from down163Stock import snatchStocks,snatchStockIndexs
from impstockfromcsv import impStockPath2Db,saveStockIntoDb,saveStockIndexIntoDb
from stockCommon import delPathFiles
from updateStockCode import updateStockCode

def main():
    updateStockCode()
    csvRootPath= os.getcwd()+os.sep+"temp"
    csvPath1 =csvRootPath+os.sep+"index"
    snatchStockIndexs(csvPath1)
    impStockPath2Db(csvPath1,saveStockIndexIntoDb)
    csvPath2 = csvRootPath+os.sep+"stock"
    snatchStocks(csvPath2)
    impStockPath2Db(csvPath2,saveStockIntoDb)
    delPathFiles(csvRootPath)
    os.removedirs(csvPath1)
    if os.path.exists(csvPath2):
        os.removedirs(csvPath2)
    if os.path.exists(csvRootPath):
        os.removedirs(csvRootPath)

    
if __name__=="__main__":
    main()